﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;
using System.Web.Configuration;
using System.Text;
using System.IO;
using System.Web.UI.WebControls;

namespace ReconUI
{
    public class MenuManager
    {
        //Initialize mysql connection
    string autoFileId;
    MySqlConnection connection;// = new MySqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
    MySqlCommand cmd;
    UserVO objUserVO;

    MySqlDataAdapter adapter;
    DataTable DTItems;

    public MenuManager()
	{
		//
		// TODO: Add constructor logic here
        connection = new MySqlConnection(WebConfigurationManager.ConnectionStrings["mySQLConnection"].ToString());
		//       
	}


    public void populateMenu(Menu menuBar,string roleId)
        {
            //Take count of newly created file id record in stagging table
            string strQuery = "SELECT * FROM conf_menu_maint where menu_id in (SELECT menu_id FROM mast_role_menu_maint where role_id = '" + roleId  + "');";
            MySqlDataAdapter adp = new MySqlDataAdapter(strQuery, connection);
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            adp.Fill(ds);       
            dt = ds.Tables[0];
            DataRow[] drowpar = dt.Select("parent_id=" + 0);

            foreach (DataRow dr in drowpar)
            {
                menuBar.Items.Add(new MenuItem(dr["menu_name"].ToString(), dr["menu_id"].ToString(),
                "", dr["menu_link"].ToString()));
            }

            foreach (DataRow dr in dt.Select("parent_id >" + 0))
            {
                MenuItem mnu = new MenuItem(dr["menu_name"].ToString(), dr["menu_id"].ToString(),
                "", dr["menu_link"].ToString());
                menuBar.FindItem(dr["parent_id"].ToString()).ChildItems.Add(mnu);
            }
            connection.Close();
        }
    }
}